home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / vol7n7.arc / PP707.ARC / TRYLCVT.ASM < prev    next >
Assembly Source File  |  1988-03-14  |  7KB  |  201 lines

  1.         name    TRYLCVT
  2.         title   TRYLCVT --- LCVT demonstration
  3.         page    55,132
  4.  
  5. ;
  6. ; TRYLCVT.ASM --- an interactive demonstration of
  7. ;                 the LCVT formatting routine
  8. ;
  9. ; To exit from the program, push <Enter>
  10. ; alone at the "Enter a number" prompt.
  11. ;
  12. ; Ray Duncan, December 1987
  13. ;
  14.  
  15. cr      equ     0dh
  16. lf      equ     0ah
  17.  
  18.  
  19. DGROUP  group   _DATA
  20.  
  21.  
  22. _TEXT   segment word public 'CODE'
  23.  
  24.         assume  cs:_TEXT,ds:_DATA
  25.  
  26.         extrn   ATOL:near               ; ASCII to long integer
  27.         extrn   LCVT:near               ; format decimal long int.
  28.         extrn   HTOL:near               ; hex ASCII to long int.
  29.  
  30. main    proc    near
  31.  
  32.         mov     ax,_DATA                ; make our data segment
  33.         mov     ds,ax                   ; addressable...
  34.         mov     es,ax
  35.         
  36.         mov     dx,offset signon        ; display sign-on message
  37.         mov     cx,so_len
  38.         call    pmsg
  39.  
  40. main1:  mov     dx,offset prompt1       ; get number to convert
  41.         mov     cx,p1_len
  42.         call    getnum
  43.         cmp     byte ptr inbuff,cr      ; was anything entered?
  44.         jne     main2                   ; yes, proceed
  45.  
  46.         mov     ax,4c00h                ; no, exit to MS-DOS
  47.         int     21h
  48.  
  49. main2:  mov     fval,ax                 ; yes, save the number
  50.         mov     fval+2,dx
  51.  
  52.         mov     dx,offset prompt2       ; get output width
  53.         mov     cx,p2_len
  54.         call    getnum
  55.         or      al,al                   ; make sure width nonzero
  56.         jz      main1                   ; jump, width was zero
  57.         mov     fwidth,al               ; else save width
  58.  
  59.         mov     dx,offset prompt3       ; get decimal places
  60.         mov     cx,p3_len
  61.         call    getnum
  62.         mov     fdecpl,al               ; and save it
  63.  
  64.         mov     dx,offset prompt4       ; get conversion flags
  65.         mov     cx,p4_len
  66.         call    getnum
  67.         mov     si,offset inbuff        ; ignore decimal value,
  68.         call    htol                    ; convert input as hex,
  69.         mov     flags,al                ; save conversion flags
  70.  
  71.         test    al,10h                  ; special pad character?
  72.         jz      main3                   ; no, jump
  73.  
  74.         mov     dx,offset prompt5       ; get pad character
  75.         mov     cx,p5_len
  76.         call    pmsg                    ; display prompt
  77.         mov     ah,1                    ; func. 1 = char. input
  78.         int     21h                     ; transfer to MS-DOS
  79.         mov     fpad,al                 ; save pad character
  80.         cmp     al,' '                  ; was it a control. char?
  81.         jae     main3                   ; no, proceed
  82.         mov     fpad,' '                ; yes, use a blank instead
  83.  
  84. main3:  mov     dx,offset display       ; display "You entered: "
  85.         mov     cx,d_len                ; to the user...
  86.         call    pmsg
  87.  
  88.                                         ; load registers and call
  89.                                         ; LCVT formatting routine...
  90.         mov     dx,fval+2               ; 32-bit number to convert
  91.         mov     ax,fval
  92.         mov     bh,fdecpl               ; number of decimal places
  93.         mov     bl,fwidth               ; output field width
  94.         mov     ch,flags                ; conversion flags
  95.         mov     cl,fpad                 ; pad character
  96.         mov     si,offset outbuff       ; DS:SI -> output buffer
  97.         call    lcvt                    ; now format the number
  98.                                         ; returns DS:SI = output
  99.                                         ; field, AX = length,
  100.                                         ; Carry = success/error
  101.  
  102.         mov     cx,ax                   ; CX = string length
  103.         mov     dx,si                   ; DS:DX = string address 
  104.         call    pmsg                    ; display formatted string
  105.  
  106.         jmp     main1                   ; do it again...
  107.  
  108. main    endp
  109.  
  110.  
  111. pmsg    proc    near                    ; display message on stdout
  112.                                         ; call with 
  113.                                         ; DS:DX = message address
  114.                                         ; CX    = message length
  115.  
  116.         mov     bx,1                    ; handle 1 = standard output
  117.         mov     ah,40h                  ; function 40h = write
  118.         int     21h                     ; transfer to MS-DOS
  119.         ret                             ; return to caller
  120.  
  121. pmsg    endp
  122.  
  123.  
  124. getnum  proc    near                    ; display prompt, get input,
  125.                                         ; and convert to binary
  126.                                         ; call with
  127.                                         ; DS:DX = prompt address
  128.                                         ; CX    = prompt length
  129.                                         ; returns
  130.                                         ; DX:AX = value entered
  131.  
  132.         call    pmsg                    ; display the prompt
  133.  
  134.         mov     dx,offset inbuff        ; read keyboard entry
  135.         mov     cx,80                   ; from the user...
  136.         mov     bx,0                    ; handle 0 = standard input
  137.         mov     ah,3fh                  ; funct. 3FH = read
  138.         int     21h                     ; transfer to MS-DOS
  139.  
  140.         mov     si,offset inbuff        ; convert convert user's 
  141.         call    atol                    ; input to binary in DX:AX
  142.  
  143.         ret                             ; return to caller
  144.  
  145. getnum  endp
  146.  
  147.  
  148. _TEXT   ends
  149.  
  150.  
  151. _DATA   segment word public 'DATA'
  152.  
  153. signon  db      cr,lf,'LCVT Demonstration Program'
  154. so_len  equ     $-signon
  155.  
  156. prompt1 db      cr,lf,lf,lf
  157.         db      'Enter a number:       '
  158. p1_len  equ     $-prompt1
  159.  
  160. prompt2 db      cr,lf
  161.         db      'Enter output width:   '
  162. p2_len  equ     $-prompt2
  163.                                                    
  164. prompt3 db      cr,lf
  165.         db      'Enter decimal places: '
  166. p3_len  equ     $-prompt3
  167.  
  168. prompt4 db      cr,lf
  169.         db      'Enter flags (hex):    '
  170. p4_len  equ     $-prompt4
  171.  
  172. prompt5 db      cr,lf
  173.         db      'Enter pad character:  '
  174. p5_len  equ     $-prompt5
  175.  
  176. display db      cr,lf,lf
  177.         db      'You entered:          '
  178. d_len   equ     $-display
  179.  
  180. fval    dw      0,0                     ; value to be formatted 
  181. flags   db      0                       ; conversion flags
  182. fwidth  db      0                       ; width of output field
  183. fdecpl  db      0                       ; decimal places
  184. fpad    db      0                       ; padding char.
  185.  
  186. inbuff  db      80 dup (?)              ; keyboard input buffer
  187.  
  188. outbuff db      80 dup (?)              ; output formatting buffer
  189.  
  190. _DATA   ends
  191.  
  192.  
  193. STACK   segment para stack 'STACK'
  194.         
  195.         db      128 dup (?)
  196.  
  197. STACK   ends
  198.  
  199.         end     main
  200.  
  201.